'use strict';

const { Controller } = require('egg');

class HouseController extends Controller {
   async index() {
      const { ctx } = this;
      ctx.body = 'hi, egg';
   }
   //获取房源列表
   async house() {
      const { ctx } = this;
      let res = await this.service.house.getHouseList();
      //  console.log(res);
      if (res.status) {
         ctx.body = {
            code: res.code,
            message: res.message,
            data: res.data
         }
      } else {
         ctx.body = {
            code: res.code,
            message: res.message,
            data: res.data
         }
      }
   }
   //删除房源信息
   async DeleteHouse() {
      const { ctx } = this;
      let params = ctx.request.body;
      let res = await this.service.house.DeleteHouse(params)
      if (res.status) {
         ctx.body = {
            code: res.code,
            message: res.message,
            data: res.data
         }
      } else {
         ctx.body = {
            code: res.code,
            message: res.message,
            data: res.data
         }
      }
   }

   //新增房源信息
   async AddHouse() {
      const { ctx } = this;
      let params = ctx.request.body;
      let res = await this.service.house.addHouse(params);
      if (res.status) {
         ctx.body = {
            code: res.code,
            message: res.message,
            data: res.data
         }
      } else {
         ctx.body = {
            code: res.code,
            message: res.message,
            data: res.data
         }
      }
   }

   //编辑房源信息
   async editHouse(){
      const { ctx } = this;
      let params = ctx.request.body;
      let res = await this.service.house.editHouse(params);
      if (res.status) {
         ctx.body = {
            code: res.code,
            message: res.message,
            data: res.data
         }
      } else {
         ctx.body = {
            code: res.code,
            message: res.message,
            data: res.data
         }
      }
   }

}

module.exports = HouseController;